import 'package:flutter/material.dart';

class NavigatorUtil {
  //跳转页面
  static Future push(
    BuildContext context,
    String routeName, {
    bool fullscreenDialog = false, //禁止正常跳转
    dynamic arguments, //参数
  }) {
    //跳转路由
    Future<dynamic> future = Navigator.of(context).pushNamed(
      routeName,
      arguments: {"fullscreenDialog": fullscreenDialog, "parameter": arguments},
    );

    return future;
  }

  // 正常返回 result返回参数
  static void pop<T extends Object>(BuildContext context, [T? result]) {
    Navigator.pop(context, result);
  }

  //返回指定页面
  static void popUntil(BuildContext context, String routeName) {
    Navigator.popUntil(context, ModalRoute.withName(routeName));
  }

  //替换当前页面
  static Future<T?> popAndPushNamed<T extends Object, TO extends Object>(
    BuildContext context,
    String routeName, {
    TO? result,
    dynamic arguments,
    bool fullscreenDialog = false, //禁止正常跳转
  }) {
    return Navigator.popAndPushNamed(
      context,
      routeName,
      result: result,
      arguments: {
        "fullscreenDialog": fullscreenDialog,
        "parameter": arguments,
      },
    );
  }

}
